home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / shade_surf_irr.pro < prev    next >
Text File  |  1997-07-08  |  4KB  |  146 lines

  1. ; $Id: shade_surf_irr.pro,v 1.5 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1989-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. pro SHADE_SURF_IRR, z, x, y, AX = ax, AZ = az, SHADES = shades, $
  7.     PLIST = plist,  IMAGE = Image, T3D = t3d
  8. ;+
  9. ; NAME:
  10. ;    SHADE_SURF_IRR
  11. ;
  12. ; PURPOSE:
  13. ;    Make a shaded surface representation of an irregulary gridded
  14. ;    elevation dataset.
  15. ;
  16. ;    The data must be representable as an array of quadrilaterals.  This 
  17. ;    routine should be used when the (X, Y, Z) arrays are too irregular to 
  18. ;    be drawn by SHADE_SURF, but are still semi-regular.
  19. ;
  20. ; CATEGORY:
  21. ;    Graphics, surface plotting.
  22. ;
  23. ; CALLING SEQUENCE:
  24. ;    SHADE_SURF_IRR, Z, X, Y
  25. ;
  26. ; INPUTS:
  27. ;    Z:    A 2D array of elevations.  This array must be dimensioned 
  28. ;        as [NX, NY].
  29. ;
  30. ;    X:    A 2D array containing the X location of each Z value.  This
  31. ;        array must be dimensioned as [NX, NY].
  32. ;
  33. ;    Y:    A 2D array containing the Y location of each Z value.  This
  34. ;        array must be dimensioned as [NX, NY].
  35. ;
  36. ; KEYWORD PARAMETERS:
  37. ;    AX:    The angle of rotation about the X axis.  The default is 30
  38. ;        degrees.  This parameter is passed to SURFR.  This keyword
  39. ;               value is ignored if the T3D keyword is set to a nonzero
  40. ;               value.  
  41. ;
  42. ;    AZ:    The angle of rotation about the Z axis.  The default is 30
  43. ;        degrees.  This parameter is passed to SURFR.  This keyword
  44. ;               value is ignored if the T3D keyword is set to a nonzero
  45. ;               value.  
  46. ;
  47. ;    IMAGE:    Set this keyword to an array that will contain the resulting
  48. ;        shaded surface image.  The variable is returned as a byte 
  49. ;        array of the same size as the currently selected graphics 
  50. ;        device.
  51. ;
  52. ;    PLIST:    Set this keyword to an array that will contain the polygon
  53. ;        list on return.  This feature is useful when you want to make a
  54. ;        number of images from the same set of vertices and polygons.
  55. ;
  56. ;       T3D:    Set this keyword to a nonzero value to indicate that the
  57. ;               generalized transformation matrix in !P.T is to be used
  58. ;               (in which case the keyword values for AX and AZ are ignored). 
  59. ;
  60. ; OUTPUTS:
  61. ;    No explicit outputs.
  62. ;
  63. ; COMMON BLOCKS:
  64. ;    None.
  65. ;
  66. ; SIDE EFFECTS:
  67. ;    The currently selected display is modified.
  68. ;
  69. ; RESTRICTIONS:
  70. ;    The grid described by X and Y must consist of quadrilaterals,
  71. ;    must be semi-regular, and must be in "CLOCKWISE" order:
  72. ;    i.e., each cell must be defined by the vertices:
  73. ;
  74. ;        v[i,j], v[i+1,j],v[i+1,j+1], and v[i,j+1].
  75. ;
  76. ;    Clockwise ordering:
  77. ;
  78. ;        x[i,j] <= x[i+1, j] ... for all j
  79. ;    and    y[i,j] <= y[i, j+1] ... for all i.
  80. ;
  81. ;    WARNING:  This restriction is not checked.
  82. ;
  83. ; PROCEDURE:
  84. ;    First, SURFR is called to establish the 3D to 2D transformation.
  85. ;    Then the vertex and polygon data structures required by the
  86. ;    POLYSHADE function are built and passed that function.  POLYSHADE
  87. ;    returns the shaded image which is then displayed by TV.
  88. ;
  89. ;    This simple procedure can be modified to use and/or accept
  90. ;    additional keywords.
  91. ;
  92. ; MODIFICATION HISTORY:
  93. ;    Oct, 1989, DMS.    
  94. ;    DMS,     Modified to use SURFR instead of SURFACE. and to return the
  95. ;        polygon list.
  96. ;       Nov, 1996, DLD: Added T3D keyword.
  97. ;-
  98.  
  99. on_error,2                      ;Return to caller if an error occurs
  100. s = size(z)
  101. if s[0] ne 2 then begin
  102.     print,'Shade - Not 2d'
  103.     return
  104.     endif
  105.  
  106. nx = s[1]            ; # of columns
  107. ny = s[2]            ; # of rows
  108.  
  109. if n_elements(ax) eq 0 then ax = 30.    ;Default rotations
  110. if n_elements(az) eq 0 then az = 30.
  111.  
  112. ;
  113. ;    Establish axis scaling:
  114. ;
  115. if (keyword_set(t3d) EQ 0) then begin
  116.   scale = 0.9            ;The fraction of the screen we use.
  117.   minx = min(x, max = maxx)
  118.   miny = min(y, max = maxy)
  119.   minz = min(z, max = maxz)
  120.  
  121.   sx = scale / (maxx - minx)    ;Scale factors
  122.   sy = scale / (maxy - miny)
  123.   sz = scale / (maxz - minz)
  124.  
  125.   !x.s = [(1.-scale)/2. - minx * sx, sx]  ;Set axis scalings
  126.   !y.s = [(1.-scale)/2. - miny * sy, sy]
  127.   !z.s = [(1.-scale)/2. - minz * sz, sz]
  128.  
  129.   surfr, ax = ax, az = az  ;establish rotation
  130.  
  131. endif
  132.  
  133. plist = intarr(5,nx-1,ny-1)    ;Make polygons
  134.  
  135. for i=0,nx-2 do for j=0,ny-2 do begin
  136.     ll = i + j*nx        ;Vertex index
  137.     plist[0,i,j] = [ 4, ll, ll+1, ll+nx+1, ll+nx]
  138.     endfor
  139. if n_elements(shades) eq 0 then $
  140.   image = polyshade(x,y,z,plist,/t3d,/data) $
  141.  else $
  142.   image = polyshade(x,y,z,plist,/t3d,/data, shades = shades)
  143.  
  144. tv, image
  145. end
  146.